 var app = getApp()
 var url = app.globalData.url
 var userTel = ""
var url1 = app.globalData.url1
 Page({

   /**
    * 页面的初始数据
    */
   data: {
     flag: false,
     names: "我的",
     list: [{
       title: '我的设备',
       desc: '',
       src: '../image/mg-equip.png',
       detail: '维修师收藏',
       slot: false,
       page: 'myequipment'
      }, {
        title: '御用维修师',
        desc: "张可用",
        slot: true,
        flag: false,
        src: '../image/mg-wxs.png',
        page: 'myenlist'
      }, {
        title: '钱包',
        desc: '',
        slot: false,
        src: '../image/mg-mony.png',
        page: 'mycoupon'
      }, {
        title: '亲友号',
        desc: '点击查看',
        flag: true,
        src: '../image/mg-fri.png',
        page: 'myfriends'
      }, {
        title: '地址管理',
        desc: '',
        detail: '维修师收藏',
        slot: false,
        flag: true,
        src: '../image/mg-addr.png',
        page: 'myaddr'
      }, {
        title: '发票管理',
        desc: '点击查看',
        slot: false,
        flag: true,
        src: '../image/mg-cop.png',
        page: 'mybill'
      }, {
        title: '我的评价',
        desc: '点击查看',
        slot: false,
        flag: true,
        src: '../image/mg-acce.png',
        page: 'myaccess'
      }, {
        title: '在线客服',
        desc: '点击查看',
        slot: false,
        flag: true,
        src: '../image/mg-kf.png',
        page: 'myconcat'
     }],
     userInfo: {},
     status: 75,
     orders:[],
     hasOrder:false
   },
   getCouponPapers() {
     const that = this
     var user = wx.getStorageSync('user')
     wx.request({
       url: url + '/coupon/usr/count_account_usable',
       data: {
         account: user.wxUsersAccount
       },
       method: "get",
       header: {
         "content-type": "application/json"
       },
       success(res) {
         if (res.data.code === 1) {
           that.setData({
             papers: res.data.data.count,
             leftovers: res.data.data.money,
             vipRank: res.data.data.member.memberName,
             watarImg: res.data.data.member.memberHead,
             backIcon: res.data.data.member.memberBackground
           })
         }
       }
     })
   },

   toEngineer(e) {
     wx.makePhoneCall({
       phoneNumber: e.currentTarget.dataset.tel,
     })
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
     const THAT = this
     var user = wx.getStorageSync("user")
   
     userTel = user.wxUsersAccount
     THAT.getCouponPapers()
     THAT.getOrders()
     THAT.getOrderNumber()
   },
   getOrderNumber(){
     const that = this
     wx.request({
       url: url+'/orders/findListCount',
       data: {
         usesAccount: userTel
       },
       header: {
         "content-type": "application/json"
       },
       success(res) {
         console.log("订单数量")
         console.log(res.data)
         if (res.data.code === 1) {
              //  var status=res.data.data.status
               that.setData({
                 badgeNum1:res.data.data[0].count,
                 badgeNum2: res.data.data[1].count,
                 badgeNum3: res.data.data[2].count,
               })
         }
       }
     })
   },
   toOther(e) {
     console.log(e)
     const page = e.currentTarget.dataset.page
     wx.navigateTo({
       url: "../equipment/equipment?page=" + page + "&index=" + e.currentTarget.dataset.index,
     })
   },
   //获取订单
   getOrders(){
     const that=this
     wx.request({
       url:  url1+'/engineer/selectEngineerHeadByOrderStatus',
       data:{
         usesAccount: userTel
       },
       header:{
         "content-type":"application/json"
       },
       success(res){
              console.log(res.data)
              if(res.data.code===1){
         
                  if(res.data.data.status === "进行中"){
                     that.setData({
                       status:75
                     })
                  }
                if (res.data.data.status === "待付款") {
                  that.setData({
                    status: 215
                  })
                }
                if (res.data.data.status === "待评价") {
                  that.setData({
                    status: 355
                  })
                }
                that.setData({
                  orders: res.data.data.ttt,
                  hasOrder: true
                })
              }else{
                that.setData({
                  orders:[],
                  hasOrder:false
                })
              }
       }
     })
   },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function() {

   },
   toOrder(e) {
     console.log(e)
     app.globalData.currentTab = e.currentTarget.id
     wx.navigateTo({
       url: '../order/order',
     })
   },
   Shouhou(){
     wx.navigateTo({
       url: '../afterSale/afterSale',
     })
   },
   /**
    * 生命周期函数--监听页面显示
    */
   onShow: function() {
     const that = this
     app.editTabBar()
     var user = wx.getStorageSync("user")
     console.log("onshow")
     console.log(user)
     userTel = user.wxUsersAccount
     that.setData({
       userInfo: user
     })
   },


   /**
    * 用户点击右上角分享
    */
   onShareAppMessage: function() {

   }
 })